% FOLDER_DATATEST='E:\NHAN\LicensePlateDetectionOnly\DataTest\DatasetA\A1';
FOLDER_DATATEST='E:\NHAN\LicensePlateDetectionOnly\TESTCHOOSE';
%% CREATE FOLDER RESULT
% FOLDER_RESULT_ALL = 'E:\NHAN\LicensePlateDetectionOnly\DataTest\DatasetA\A1\RESULT_NEW_CROSSOBJECT';
FOLDER_RESULT_ALL = 'E:\NHAN\LicensePlateDetectionOnly\TESTCHOOSE\REULST';

%% SETUP CONFIG
% congif parameter
IS_DEBUG = true;
% get Sauvola config
conSauvola_k = 0.1;
conSauvola_R = 128;
conSauvola_b = 10;
conSauvola = [conSauvola_k conSauvola_R conSauvola_b];

% get Filter 1 config
conFilter1_Aspect = 0.5;
conFilter1_Orientation = 35;
conFilter1_Euler = 3;
conFilter1 = [conFilter1_Aspect conFilter1_Orientation conFilter1_Euler];

%get Filter 2 config
conFilter2_height = 0.45;
conFilter2_width = 0.2;
conFilter2_nLeast = 4;
conFilter2_nRecheck = 2;
conFilter2 = [conFilter2_height conFilter2_width conFilter2_nLeast conFilter2_nRecheck];

%% GET ALL FILE
allFiles = dir(FOLDER_DATATEST);
filename = { allFiles.name };
for i=3:length(filename)
    chec = 0;
    if (strfind(filename{i},'.JPG')>0)
        chec = 1;
    end
    if (strfind(filename{i},'.jpg')>0)
        chec = 1;
    end
    if (strfind(filename{i},'.bmp')>0)
        chec = 1;
    end
    if (chec)
        [pathstr, name, ext] = fileparts(filename{i});
        fid = fopen(strcat(FOLDER_RESULT_ALL,'\','logResult.txt'), 'at');
        %write to file name of file
        fprintf(fid, '%d %s ', i, filename{i});
        
        Io = imread(strcat(FOLDER_DATATEST,'\',filename{i}));  % nhap buc anh goc va gan vao I1
        [x y z] = size(Io);
        if z==3
            Io = rgb2gray(Io);
        end
        
        [lsImage lsCharacter lsPosition ] = main( Io, true, ...
            filename{i}, FOLDER_RESULT_ALL,  conSauvola, conFilter1, conFilter2 );
        listImage = lsImage;
        
        for j=1:length(listImage)
            imwrite(listImage{j},strcat(FOLDER_RESULT_ALL,'\', ...
                name,'refinal',num2str(j),'char-',ext),'bmp');
        end
        %write to file name of file
        fprintf(fid, ' %d \n', length(listImage));
        % dong file text lai
        fclose(fid);
        clear fid;
    end
end